<%@ page import="java.util.ArrayList" %><%--
  Created by IntelliJ IDEA.
  User: 白菜你个cabbage
  Date: 2019/11/7
  Time: 11:31
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>购物车页面</title>
</head>
<body>
图书分类>>>
<a href="historyBook.jsp">历史类图书</a>
<a href="IT.jsp">计算机类图书</a><br>
<p>>>>我的购物车</p><br>
<%
    request.setCharacterEncoding("utf-8");
    ArrayList books = (ArrayList) session.getAttribute("books");
    for (int i = 0; i < books.size(); i++) {
        if (books.get(i) != null) {
            String ss = (String) books.get(i);
            //将已添加到购物车的图书信息保存在表单中
%>
<form action="" method="post">
    <input type="text" name="book" value="<%= ss%>" size="40" maxlength="200" readonly>
    <input type="submit" value="删除">
</form>
<%
        }
    }
    //获取要删除的图书的信息
    String delbook = request.getParameter("book");
    if (delbook != null) {
        //out.println("要删除的书是 "+delbook+"<br>");
        for (int j = 0; j < books.size(); j++) {
            String book = (String) books.get(j);
            if (book == null) {
                books.remove(j);
            }
            if (book != null && book.indexOf(delbook) != -1) {
                books.remove(j);
                //刷新当前页面
%>
<script type="text/javaScript">
    alert("删除成功");
    window.location.href = window.location.href;
</script>
<%
                break;
            }
        }
    }
%>

</body>
</html>
